package com.example.demo.controller;

import com.example.demo.entity.*;
import com.example.demo.mapper.*;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Date;
import java.util.List;

@RestController
public class FeedbackController {

    @Autowired
    FeedbackMapper feedbackMapper;

    @RequestMapping("/getAllFeedback")
    public List<Feedback> getAllFeedback()
    {
        List<Feedback> feedbacks = feedbackMapper.getAllfeedback();

        for(Feedback feedback : feedbacks)
        {
            int detecId = feedback.getDetectorID();
            int responId=feedback.getSponsorID();

            feedback.setDetecName(feedbackMapper.finduRealNameById(detecId));
            feedback.setSponsorName(feedbackMapper.finduRealNameById(responId));
        }

        return feedbacks;
    }

    @PatchMapping("/addResponse")
    public int addResponse(int spoid, String response, String restime, int backid)
    {
        return feedbackMapper.addResponse(spoid,response,restime,backid);
    }

    @RequestMapping("/getBackAndSpo")
    public Feedback findBackAndSpoById(int backid)
    {
        Feedback feedback = feedbackMapper.findBackAndSpoById(backid);
        return feedback;
    }
}
